<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Service\SubService;

use EasyWeChat\MiniApp\Application;
use Hyperf\Codec\Json;
use Hyperf\Di\Annotation\Inject;

class WechatService
{
    #[Inject]
    protected Application $application;

    public function login(string $code)
    {
        $api = $this->application->getClient();
        return Json::decode($api->get('/sns/jscode2session', [
            'appid' => $this->application->getAccount()->getAppId(),
            'secret' => $this->application->getAccount()->getSecret(),
            'js_code' => $code,
            'grant_type' => 'authorization_code',
        ])->getContent());
    }
}
